package com.lq.order.service.impl;

import com.lq.order.entity.OrderItem;
import com.lq.order.mapper.OrderItemMapper;
import com.lq.order.service.IOrderItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 订单项表 服务实现类
 * </p>
 *
 * @author lq
 * @since 2025-08-22
 */
@Service
@AllArgsConstructor
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements IOrderItemService {

    public StringRedisTemplate redisTemplate;

    @Override
    public List<OrderItem> getOrderItemsByOrderId(Long orderId) {
        return this.lambdaQuery().eq(OrderItem::getOrderId, orderId).list();
    }
    
    @Override
    public boolean saveBatchOrderItems(List<OrderItem> orderItems) {
        // 设置创建和更新时间
        orderItems.forEach(item -> {
            item.setCreateTime(LocalDateTime.now());
            item.setUpdateTime(LocalDateTime.now());
        });
        return this.saveBatch(orderItems);
    }

    @Override
    public boolean removeOrderItemsByOrderId(Long orderId) {
        return this.remove(lambdaQuery().eq(OrderItem::getOrderId, orderId));
    }

}